% Calculates curve for given bottle model as angle = f(liquid volume)

%% init data
clear all;
bottle_x=[0 1 1.8 1.8 2 2.2 2.2 3:29 28.5 28.2 27.8 27.5];
bottle_y=[1.3 1.3 1.3 1.8 1.8 1.8 1.5 1.6 2.1 2.5 2.9 3.2 3.6 3.9 4 4 4 4 4 4 4 4 4 4 3.9 3.8 3.7 3.6 3.8 3.9 4 4 3.6 3 2.3 1.8 1.5 0];
bottle_cap_x=[1.4 0 0 0 1.4];
bottle_cap_y=[-1.5 -1.5 0 1.5 1.5];
liquid_volume = (0.1:5:185.1)/1.851; % units?
liquid_density = 500/185; % 
bottle_mass = 73; %grams
cap_mass = 1; %grams

[bottle_mass_center, bottle_shape, cap_mass_center] = bottle_model(bottle_x, bottle_y, bottle_cap_x, bottle_cap_y);

% mode parameters structure:
% - mode_name                 - 'mesh' or 'monte_carlo'
% - monte_carlo_points_number - number of points in monte carlo integration
% - vertices                  - coordinates of vertices in triangulation
%                               (we make triangulation in tipping_angle)
% - triangles                 - 
% - rotation_angle            - rotation angle (you should set this
%                               parameter before drawing plots in mesh mode)
mode_parameters.mode_name = 'mesh';
mode_parameters.monte_carlo_points_number = 500;
edge_length = 3;%min_bottle_poly_distance(bottle_shape);
[mode_parameters.vertices mode_parameters.triangles] = triangulation(bottle_shape, edge_length);
mode_parameters.rotation_angle = 0;
%% calculate results
angle = zeros(1, length(liquid_volume));
for i=1:length(liquid_volume)
tic;
angle(i) = tipping_angle(liquid_volume(i), liquid_density, bottle_shape, bottle_mass,...
                                      bottle_mass_center, cap_mass, cap_mass_center, mode_parameters);
toc    
end;
%% plot results
close all;
figure;
plot(liquid_volume, -angle, 'r-');
hold on;